package com.hongning.railway.ui.main.fragments.threesessionsandonelesson;

import android.app.Application;
import android.databinding.ObservableArrayList;
import android.databinding.ObservableList;
import android.support.annotation.NonNull;
import android.view.View;

import com.hongning.railway.BR;
import com.hongning.railway.R;
import com.hongning.railway.app.Constant;
import com.hongning.railway.data.AppRepository;
import com.hongning.railway.entity.reqbean.MettingMessageBean;
import com.hongning.railway.entity.reqbean.ThreesessionSanDoneLessonBean;
import com.hongning.railway.ui.main.fragments.home.itemviewmodel.MineItemViewModel;
import com.hongning.railway.ui.main.fragments.home.itemviewmodel.ThreesessionSanDoneLessonItemViewModel;
import com.hongning.railway.ui.main.fragments.home.itemviewmodel.ThreesessionSanDoneLessonMsgItemViewModel;
import com.hongning.railway.util.Apputils;

import java.util.List;

import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Action;
import io.reactivex.functions.Consumer;
import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.http.ApiDisposableObserver;
import me.goldze.mvvmhabit.utils.RxUtils;
import me.goldze.mvvmhabit.utils.ToastUtils;
import me.tatarka.bindingcollectionadapter2.ItemBinding;

public class ThreesessionSanDoneLessonMsgViewModel extends BaseViewModel<AppRepository> {
    public ObservableList<ThreesessionSanDoneLessonMsgItemViewModel> viewlist=new ObservableArrayList<>();
    public ItemBinding<ThreesessionSanDoneLessonMsgItemViewModel> itemBinding = ItemBinding.of(BR.msgItemViewModel, R.layout.activity_threesessionsandonelesson_msg_item);

    public ThreesessionSanDoneLessonMsgViewModel(@NonNull Application application, AppRepository model) {
        super(application, model);
    }
    public void click(int index)
    {
        finish();
    }

    public void initDatas(MettingMessageBean mettingMessageBean){
        mettingMessageBean.setStaffid(Apputils.getUserId());
        mettingMessageBean.setSigncolumn("0");
        model.selectMessage(mettingMessageBean)
                .compose(RxUtils.schedulersTransformer()) //线程调度
                .compose(RxUtils.bindToLifecycle(getLifecycleProvider()))
                .doOnSubscribe(new Consumer<Disposable>() {
                    @Override
                    public void accept(Disposable disposable) throws Exception {
                        showDialog();
                    }
                }).doOnTerminate(new Action() {
            @Override
            public void run() throws Exception {
                dismissDialog();
            }
        }).subscribe(new ApiDisposableObserver<List<ThreesessionSanDoneLessonBean.DataBean> >() {
            @Override
            public void onResult(List<ThreesessionSanDoneLessonBean.DataBean> responses) {
                 if (responses==null||responses.isEmpty())
                 {
                     ToastUtils.showShort("无数据");
                     return;
                 }
                for (ThreesessionSanDoneLessonBean.DataBean dataBean:responses) {
                    viewlist.add(new ThreesessionSanDoneLessonMsgItemViewModel(ThreesessionSanDoneLessonMsgViewModel.this,dataBean));
                }
            }
        });
    }
}
